import { JsonProperty, Serializable } from '@/plugins/reflect-metadata';

import { CardFormType } from '../const';

@Serializable()
export default class CardConfig {
  @JsonProperty('showPicker')
    showPicker: boolean = false;

  @JsonProperty('submitType')
    submitType: number = 0;

  @JsonProperty('productCode')
    productCode: number = 0;

  @JsonProperty('faceValue')
    faceValue: number = 0;

  @JsonProperty('faceValueList')
    faceValueList: number[] = [];

  @JsonProperty('cardPlatform')
    cardPlatform: string = 'xunka';

  @JsonProperty('formType')
    formType: number = CardFormType.CardNumberAndPassword;

  @JsonProperty('cardNumber')
    cardNumber: string = '';

  @JsonProperty('cardPassword')
    cardPassword: string = '';

  @JsonProperty('cardInfoList')
    cardInfoList: string = '';

  get single() {
    if (this.formType === CardFormType.CardNumberAndPassword) {
      return {
        submitType: this.submitType,
        productCode: this.productCode,
        faceValue: this.faceValue,
        cardPlatform: this.cardPlatform,
        formType: this.formType,
        cardInfoList: [`${this.cardNumber} ${this.cardPassword}`],
      };
    }
    if (this.formType === CardFormType.CardNumber) {
      return {
        submitType: this.submitType,
        productCode: this.productCode,
        faceValue: this.faceValue,
        cardPlatform: this.cardPlatform,
        formType: this.formType,
        cardInfoList: [this.cardNumber],
      };
    }

    return {
      submitType: this.submitType,
      productCode: this.productCode,
      faceValue: this.faceValue,
      cardPlatform: this.cardPlatform,
      formType: this.formType,
      cardInfoList: [this.cardPassword],
    };
  }

  get batch() {
    return {
      submitType: this.submitType,
      productCode: this.productCode,
      faceValue: this.faceValue,
      cardPlatform: this.cardPlatform,
      formType: this.formType,
      cardInfoList: this.cardInfoList.split('\n').filter((item) => item),
    };
  }
}
